package com.carcenter.personnel.service.impl;

import com.carcenter.personnel.entity.Roles;
import com.carcenter.personnel.mapper.RolesMapper;
import com.carcenter.personnel.service.IRolesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author car
 * @since 2025-07-16
 */
@Service
public class RolesServiceImpl extends ServiceImpl<RolesMapper, Roles> implements IRolesService {
    @Autowired
    private RolesMapper roleMapper;

    @Override
    public Map<Integer, String> getRoleNamesByIds(List<Integer> roleIds) {
        if (roleIds == null || roleIds.isEmpty()) {
            return Collections.emptyMap();
        }

        List<Roles> roles = roleMapper.selectBatchIds(roleIds);

        // 返回 Map<roleId, roleName>
        return roles.stream()
                .collect(Collectors.toMap(
                        Roles::getId,
                        Roles::getRoleName
                ));
    }
}
